<?php

//get the special NPC from players list
function getLocationNPC($player){
    
    $playerX = $player->loc_x;
    $playerY = $player->loc_y;
    
    $query = "SELECT * FROM `player` WHERE `facebook_id` < 100 AND `loc_x`=$playerX AND `loc_y`=$playerY LIMIT 0,1 ";
    
    $result = mysql_query($query);
    
    if ($result) {
        $row = mysql_fetch_object($result);
    }
    
    return $row;
    
}


function displayLocationNPC($locationNPC){

?>
            <table class="review_display" width="100%"> 
                <tr>
                    <td class="review_pic_column">
                        <div class="review_pic"><img src="<? echo IMAGE_HOST_URL."$locationNPC->image"; ?>" alt="" class="" /></div>
                    </td>
                    <td>
                        <table width="100%"> <tr><td>
                        <div class="review_header"> <div class="review_header_title_line">
                        <div class="review_header_title"><? echo $locationNPC->name; ?></div> </div> 
                        <div class="review_header_subtitle_line"></div></div>
                        <div class="review_body"><? echo $locationNPC->comment; ?>
                        </div>
                        </td> 
                        </tr>
                        </table>                
                    </td> 
                </tr> 
            </table>
            <br/><hr/>
<?

}

function displayLocation($location) {
    
?>
            <table class="review_display" width="100%"> 
                <tr>
                    <td class="review_pic_column">
                        <div class="review_pic"><img src="<? echo IMAGE_HOST_URL."images/map/$location->image"; ?>" alt="" class="" /></div>
                    </td>
                    <td>
                        <table width="100%"> <tr><td>
                        <div class="review_header"> <div class="review_header_title_line">
                        <div class="review_header_title">Visiting <? echo $location->name; ?></div> </div> 
                        <div class="review_header_subtitle_line"><? echo getLocationType($location->type); ?></div></div>
                        <div class="review_body"><? echo $location->desc; ?>
                        </div>
                        </td> 
                        </tr>
                        </table>                
                    </td> 
                </tr> 
            </table>
<?

}

function displayNPCItems($locationNPC){

    $NPC_X = $locationNPC->loc_x;
    $NPC_Y = $locationNPC->loc_y;
    
    $query = "SELECT * FROM `player_items_view` WHERE `player_id` = $locationNPC->id LIMIT 0, 5";
    
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_object($result)) {
?>
            <table class="review_display" width="100%"> 
                <tr>
                    <td class="review_pic_column">
                        <div class="review_pic"><img src="<? echo IMAGE_HOST_URL."$row->image"; ?>" alt="" class="" /></div>
                    </td>
                    <td>
                        <table width="100%"> <tr><td>
                        <div class="review_header"> <div class="review_header_title_line">
                        <div class="review_header_title"><? echo $row->name; ?></div> </div> 
                        <div class="review_header_subtitle_line"><? echo "Power: $row->power, Price: $row->price coins."; ?></div></div>
                        <div class="review_body"><? echo $row->desc; ?><br/>
                        <form method="post" action="<? echo FACEBOOK_URL; ?>index.php">
                        <input type="hidden" name="item_id" value="<? echo $row->playeritems_id; ?>">
                        <input type="submit" name="buy" value="Buy">
                        </form>
                        </div>
                        </td> 
                        </tr>
                        </table>                
                    </td> 
                </tr> 
            </table>
            <br/><hr/>
<?
    }
}


//
function getPlaceData($mapPlaceID) {
    
    $query = "SELECT * `place` WHERE `id` = $mapPlaceID LIMIT 0,1";
    
    $result = mysql_query($query);
    
    if ($result) {
        $row = mysql_fetch_object($result);
    }
    
    return $row;
    
}

  
?>
